﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Media;

namespace WindowsGame1.View
{
    class Sound
    {
        //ljud
        private SoundEffect _jumpSound;
        private SoundEffect _eatingCarrotSound;
        private SoundEffect _explosionSound;
        private Song _backgroundMusic;

        bool songStart = false;

        //konstruktor som läser in nödvändiga ljud
        public Sound(ContentManager a_contentManager)
        {
            _jumpSound = a_contentManager.Load<SoundEffect>("jump");
            _eatingCarrotSound = a_contentManager.Load<SoundEffect>("carrotnom");
            _explosionSound = a_contentManager.Load<SoundEffect>("explosion");
            _backgroundMusic = a_contentManager.Load<Song>("backgroundMusic");
            MediaPlayer.IsRepeating = true;

            PlayBackgroundMusic();
        }

        //metod för att spela upp musik
        private void PlayBackgroundMusic()
        {
            if (!songStart)
            {
                MediaPlayer.Play(_backgroundMusic);
                songStart = true;
            }  
        }

        //metod för att spela upp ljud
        private void PlaySound(SoundEffect a_sound)
        {
            if (a_sound != null)
            {
                a_sound.Play();
            }
        }
        
        //metod för att spela upp "äta morot"
        public void PlayEatingCarrotSound()
        {
            PlaySound(_eatingCarrotSound);
        }

        //metod för att spela upp exploderande ljud
        public void PlayExplodingSound()
        {
            PlaySound(_explosionSound);
        }

        //metod för att spela upp hopp-ljud
        public void PlayJumpSound()
        {
            PlaySound(_jumpSound);
        }
    }
}
